package com.future.mayi.activity;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;

import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.app.App;
import com.future.mayi.response.MsgDetailResponse;
import com.future.mayi.utils.HtmlFormat;

import butterknife.BindView;

public class MsgDetailActivity extends BaseTitleActivity {
    @BindView(R.id.web_view)
    WebView webView;

    private String msgId;

    public static void startActivity(Context context, String msgId) {
        Intent intent = new Intent(context, MsgDetailActivity.class);
        intent.putExtra("msgId", msgId);
        context.startActivity(intent);
    }

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("消息详情");

    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_msg_detail);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {

        msgId = getIntent().getStringExtra("msgId");

        new HttpRequest<MsgDetailResponse>()
                .with(this)
                .setApiCode(ApiCst.detailMsg)
                .addParam("token", App.getToken(mContext))
                .addParam("msg_id", msgId)
                .setListener(new HttpRequest.OnNetworkListener<MsgDetailResponse>() {
                    @Override
                    public void onSuccess(MsgDetailResponse response) {
                        if (response.model != null)
                            webView.loadDataWithBaseURL(null, HtmlFormat.getNewContent(response.model.getContent()), "text/html", "utf-8", null);
                    }

                    @Override
                    public void onFail(String message, MsgDetailResponse response) {
                        toast(message);
                    }
                }).start(new MsgDetailResponse());
    }

    @Override
    protected void initListener() {

    }
}
